package com.t2t.top.rocketmq.spring;

import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import com.alibaba.rocketmq.common.message.Message;
import com.alibaba.rocketmq.common.message.MessageExt;
import com.t2t.top.rocketmq.spring.ExampleMessageListener;

import java.util.List;

/**
 * 业务监听实现类.
 * <p/>
 * Created by yangpengfei on 2015/11/3.
 */
public class SimpleExampleMessageListener implements ExampleMessageListener {

    /**
     * 接收消息.
     *
     * @param messages 消息体
     * @param context  上下文
     * @return 是接收成功
     */
    public boolean onMessage(List<MessageExt> messages, ConsumeConcurrentlyContext context) {
        System.out.println("接收消息：");
        for (int i = 0; i < messages.size(); i++) {
            Message msg = messages.get(i);
            System.out.println(msg.toString());
            System.out.println(msg.getTopic() + " : " + new String(msg.getBody()));
        }
        return true;
    }

}
